package class03_一些基础的数据结构.test;

/**
 * 链表节点的删除
 */
public class Code02_DeleteGivenValue {
    public static class Node{
        int value;
        Node next;
    }
    public static Node removeValue(Node head,int val){
        //删除的节点等于头节点
        while (head != null && head.value == val){
            head = head.next;
        }
        Node pre = null;
        Node cur = head;
        while (cur != null){
            if(cur.value == val){
                pre.next = cur.next;
            }else {
                pre = cur;
            }
            cur = cur.next;
        }
        return head;
    }
}
